package com.ray.ba.starter.web.api;

import com.github.pagehelper.PageInfo;
import lombok.Data;

import java.util.List;

/**
 * 分页数据封装类
 * Created by macro on 2019/4/19.
 */

@Data
public class ResponsePage<T>{
    private Integer pageNum;
    private Integer pageSize;
    private Long total;
    private List<T> list;

    protected ResponsePage() {
    }

    public static <T> ResponsePage<T> getInstance(Integer pageNum, Integer pageSize, Long total, List<T> rows) {
        ResponsePage<T> responsePage = new ResponsePage<>();
        responsePage.setPageNum(pageNum);
        responsePage.setPageSize(pageSize);
        responsePage.setTotal(total);
        responsePage.setList(rows);
        return responsePage;
    }
    /**
     * 将PageHelper分页后的list转为分页信息
     */
    public static <T> ResponsePage<T> restPage(List<T> list) {
        ResponsePage<T> result = new ResponsePage<T>();
        PageInfo<T> pageInfo = new PageInfo<T>(list);
        result.setPageNum(pageInfo.getPageNum());
        result.setPageSize(pageInfo.getPageSize());
        result.setTotal(pageInfo.getTotal());
        result.setList(pageInfo.getList());
        return result;
    }



}
